<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

class PimModelProduct extends JModel {
	
	function __construct() {
		parent::__construct();
	}
	
	function count($where) {
		$query = "SELECT count(id) FROM #__product $where";
		$this->_db->setQuery($query);
		return $this->_db->loadResult();
	}
	
	function getData(&$total, &$dbrows , $order_by = 'id', $order_dir = 'DESC', $offset = 0, $limit = 30, $where=array()) {
		if (sizeof($where) > 0)
			$where = 'WHERE ' . implode(' AND ', $where);
		else
			$where = '';

		if ($limit !== 0)
			$limit = "LIMIT $offset, $limit";
		else
			$limit = '';
			
		$query = "SELECT * FROM #__product $where ORDER BY $order_by $order_dir $limit";

		$this->_db->setQuery($query);
		$dbrows = $this->_db->loadObjectList();

		$total = $this->count($where);
	}
}